package fr.upmc.aladyn.transactionables.javassist.metaobject;

import javassist.CannotCompileException;
import javassist.NotFoundException;
import javassist.tools.reflect.Loader;

/**
 * <p>Run a program with Metaobjects</p>
 * @author Alexis Deluze
 *
 */
public class MainTestApplicationMetaobjectWithThreads {

	public static void main(String[] args) {
	
		String[] argsMain = new String[0];
		Loader l;
		
		/*
		 * Uncomment to use dynamic loading (via args)
		if (args.length > 0) {
			argsMain = new String[args.length - 1];
			for (int i = 1; i < args.length; i++) {
				argsMain[i - 1] = args[i];
			}
		} else {
			System.out.println("[META MAIN] Usage : Vous devez passer en parametre le main puis les classes qu'il utilise.\n\tExemple :");
			System.out.println("\t\tfr.upmc.aladyn.transactionables.tests.Test\n\t\tfr.upmc.aladyn.transactionables.tests.objects.Point\n\t\tfr.upmc.aladyn.transactionables.tests.objects.ColoredPoint");
			System.exit(0);
		}
		*/
		args = new String[] {
				"fr.upmc.aladyn.transactionables.tests.application.MainWithThreads",
				"fr.upmc.aladyn.transactionables.tests.application.Personne",
				"fr.upmc.aladyn.transactionables.tests.application.Adulte",
				"fr.upmc.aladyn.transactionables.tests.application.Enfant",
				"fr.upmc.aladyn.transactionables.tests.application.EtatCivil",
				"fr.upmc.aladyn.transactionables.tests.application.Couple"
		};
		argsMain = new String [] {};
		
		try {
			l = new Loader();
			for(String c : args){
				System.out.println("[META MAIN] Passage de la classe "+c+" en reflexive.");
				l.makeReflective(
					c,
					"fr.upmc.aladyn.transactionables.javassist.metaobject.TransactionableMetaobject",
					"javassist.tools.reflect.ClassMetaobject"
				);
			}
			l.run(args[0], argsMain);
			
		} catch (CannotCompileException | NotFoundException e1) {
			e1.printStackTrace();
		} catch (Throwable e2) {
			e2.printStackTrace();
		}
	}
}